'''
工地档案
'''
from Lib.base.keywords import KeyWords
from selenium.webdriver.common.by import By
from Lib.common.common_function import *
from Lib.base.page_object.login_page import LonginPage


class SiteRecord(KeyWords):
    url = KeyWords.url + 'worksite-archive/query'
    # 查询工地列表相关操作
    # 根据分类分级进行筛选
    kind = (By.XPATH, '//input[@placeholder="请选择事件等级"]')
    kind_value1 = (By.XPATH, '//span[text()="绿色"]')
    kind_value2 = (By.XPATH, '//div[@x-placement="bottom-start"]//span[text()="不限"]')
    # 根据工程类型进行筛选
    site_type = (By.XPATH, '//input[@placeholder="请选择"]')
    site_type_value1 = (By.XPATH, '//div[@x-placement="bottom-start"]//span[text()="房屋建筑"]')
    site_type_value2 = (By.XPATH, '//div[@x-placement="bottom-start"]//span[text()="不限"]')

    # ----------------------根据关键词搜索，并查看详情-------------------------------
    search_input = (By.XPATH, '//input[contains(@placeholder, "请输入项目名称/地址/项目编码/报建编号")]')
    search_button = (By.XPATH, '//i[contains(@class, "rz-icon-search")]')
    search_clear = (By.XPATH, '//i[contains(@class, "rz-input__clear")]')
    # 查看详情
    detail_button = (By.XPATH, '//table[@class="rz-table__body"]//tr[1]//span[text()="查看详情"]')

    # ----------------------根据关键词搜索，并修改分类分级-------------------------------
    # 分类分级
    update_button = (By.XPATH, '//table[@class="rz-table__body"]//tr[1]//span[text()="修改分级分类"]')
    # 选择等级
    change_color_red = (By.XPATH, '//div[@class="risk-item isActive"]/..//div[contains(text(),"红色")]')
    change_sure = (By.XPATH, '//span[text()="确定"]')
    # 恢复等级
    change_color_green = (By.XPATH, '//div[@class="risk-item isActive"]/..//div[contains(text(),"绿色")]')

    def site_record_list(self):
        '''
        工地档案列表查询
        :return:
        '''
        self.open(self.url)
        self.wait(2)
        # 根据分类分级进行筛选
        self.click(args=self.kind, context="分类分级")
        self.wait(1)
        self.click(args=self.kind_value1, context="绿色")
        self.wait(1)
        self.click(args=self.kind, context="分类分级")
        self.wait(1)
        self.click(args=self.kind_value2, context="不限")
        self.wait(1)
        # 根据工程类型进行筛选
        self.click(args=self.site_type, context="工程类型")
        self.wait(1)
        self.click(args=self.site_type_value2, context="不限")
        self.wait(1)
        self.click(args=self.site_type, context="工程类型")
        self.wait(1)
        self.click(args=self.site_type_value1, context="房屋建筑")
        self.wait(1)

    def site_record_search_detail(self):
        '''
        搜索工地 并查看详情
        :return:
        '''
        self.open(self.url)
        self.wait(2)
        # 根据地址进行搜索
        self.input_value(args=self.search_input, text="漕河泾", context="搜索输入框")
        self.click(args=self.search_button, context="搜索按钮")
        self.wait(1)
        self.hover(args=self.search_input, context="搜索输入框")
        self.click(args=self.search_clear, context="清空")
        # 根据项目编码进行搜索
        self.input_value(args=self.search_input, text="07", context="搜索输入框")
        self.click(args=self.search_button, context="搜索按钮")
        self.wait(1)
        self.hover(args=self.search_input, context="搜索输入框")
        self.click(args=self.search_clear, context="清空")
        # 根据报建编号
        self.input_value(args=self.search_input, text="编号", context="搜索输入框")
        self.click(args=self.search_button, context="搜索按钮")
        self.wait(1)
        self.hover(args=self.search_input, context="搜索输入框")
        self.click(args=self.search_clear, context="清空")
        # 根据项目名称进行搜索
        self.input_value(args=self.search_input, text="项目", context="搜索输入框")
        self.click(args=self.search_button, context="搜索按钮")
        self.wait(1)
        self.click(args=self.detail_button, context="查看详情")
        self.wait(1)

    def site_record_search_update(self):
        '''
        修改工地分类等级
        :return:
        '''
        self.open(self.url)
        self.wait(2)
        # 根据项目名称进行搜索
        self.input_value(args=self.search_input, text="项目", context="搜索输入框")
        self.click(args=self.search_button, context="搜索按钮")
        self.wait(1)
        self.click(args=self.update_button, context="修改分级分类")
        self.wait(1)
        self.click(args=self.change_color_red, context="红色")
        self.wait(1)
        self.click(args=self.change_sure, context="确定")
        self.wait(1)
        self.click(args=self.update_button, context="修改分类分级")
        self.wait(1)
        self.click(args=self.change_color_green, context="绿色")
        self.wait(1)
        self.click(args=self.change_sure, context="确认")
        self.wait(1)
        self.click(args=self.detail_button, context="查看详情")


if __name__ == '__main__':
    driver = choose_browser()
    L = LonginPage(driver)
    L.login('kobekq1', 'kobe8888')
    case = SiteRecord(driver)
    case.site_record_search_update()
